package com.cincc.cinccimdemo.ui.me.favorite.viewholder;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.RecyclerView;

import com.cincc.cinccimdemo.R;
import com.cincc.cinccimdemo.common.TimeUtils;
import com.cincc.cinccimdemo.ui.me.favorite.FavoriteListActivity;
import com.cincc.im.model.CollectModel;

public abstract class FavContentViewHolder extends RecyclerView.ViewHolder {
    TextView senderTextView;
    TextView timeTextView;

    protected Activity mContext;
    protected CollectModel favoriteItem;

    public FavContentViewHolder(@NonNull View itemView) {
        super(itemView);
        bindViews(itemView);
    }

    private void bindViews(View itemView) {
        senderTextView = itemView.findViewById(R.id.senderTextView);
        timeTextView = itemView.findViewById(R.id.timeTextView);
        itemView.findViewById(R.id.favContentContainerLinearLayout).setOnLongClickListener(v -> this.onLongClick());
        itemView.findViewById(R.id.favContentContainerLinearLayout).setOnClickListener(v -> this.onClick());
    }

    public void bind(Activity context, CollectModel item) {
        this.mContext = context;
        this.favoriteItem = item;
        senderTextView.setText(TextUtils.isEmpty(item.groupName) ? item.fromUserName : item.groupName);
        timeTextView.setText((TimeUtils.getMsgFormatTime1(item.sendTime)));
    }

    public boolean onLongClick() {
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setTitle("提示");
        builder.setMessage("确定要删除吗？");
        builder.setNegativeButton("取消", null);
        builder.setPositiveButton("确定", (dialog, which) -> ((FavoriteListActivity) mContext).delFav(favoriteItem));
        builder.show();
        return true;
    }

    protected void onClick() {

    }
}
